from django.db import models
from django.contrib import admin
from django.contrib.auth.models import User
import datetime

class Tipo_anime(models.Model):
    nombre = models.CharField(max_length=30)
    def __unicode__(self):
        return self.nombre
    
class DatosExtra(models.Model):
    user = models.OneToOneField(User)
    edad = models.IntegerField()
    sexo = models.CharField(max_length=9)
    
class Categoria_anime(models.Model):
    nombre = models.CharField(max_length=30)
    def __unicode__(self):
        return self.nombre
    
class Anime(models.Model):
    fecha_public = models.DateTimeField('Fecha de publicacion',auto_now_add=True)
    seccion_anime = models.ForeignKey(User)
    categoria = models.ForeignKey(Categoria_anime)
    tipo = models.ForeignKey(Tipo_anime)
    nombre = models.CharField(max_length=100)
    link_principal = models.CharField(max_length=100)
    link_apoyo = models.CharField(max_length=100)
    ranking = models.IntegerField(max_length=30)
    def __unicode__(self):
        return self.nombre
    def votar(self):
        self.ranking = self.ranking + 1
    def establecerRanking(self):
        return self.ranking == 0
        
class Seccion(models.Model):
    nombre = models.CharField(max_length=30)
    def __unicode__(self):
        return self.nombre
    
class Link(models.Model):
    nombre = models.CharField(max_length=30)
    def __unicode__(self):
        return self.nombre
    
class Biblioteca(models.Model):
    nombre = models.CharField(max_length=30)
    seccion = models.ForeignKey(User)
    animes = models.ManyToManyField(Anime)
    def __unicode__(self):
        return self.nombre

    class Media:
        css = { "all": ("default.css",) }

from django import forms
from django.forms import ModelForm

class AnimeForm(ModelForm):
    class Meta:
        model = Anime
        exclude = ['ranking', 'seccion_anime']
        
